var express = require('express');
var router = express.Router();

/* GET home page. */

router.get('/permission', function(req, res, next) {
  if (req.query.userId === '1') {
    res.send({
      code: 200,
      success: true,
      message: '获取权限成功',
      result: [{
        name: 'Set'
      }, {
        name: 'File',
        children: [{
          name: 'file1',
          btns: ['download']
        },{
          name: 'file3'
        }]
      }]
    })
  } else if (req.query.userId === '2') {
    res.send({
      code: 200,
      success: true,
      message: '获取权限成功',
      result: [{
        name: 'Voice'
      }]
    })
  } else if (req.query.userId === '3') {
    res.send({
      code: 200,
      success: true,
      message: '获取权限成功',
      result: [{
        name: 'Set'
      }, {
        name: 'File',
        children: [{
          name: 'file2'
        },{
          name: 'file3'
        }]
      }]
    })
  }
})

router.get('/login', function(req,res,next) {
  if (req.query.name === 'root') {
    res.send({
      code: 200,
      success: true,
      message: '登录成功',
      userId: 1
    })
  } else if (req.query.name === 'admin') {
    res.send({
      code: 200,
      success: true,
      message: '登录成功',
      userId: 2
    })
  } else if (req.query.name === 'test') {
    res.send({
      code: 200,
      success: true,
      message: '登录成功',
      userId: 3
    })
  }else {
    res.send({
      code: 200,
      success: false,
      message: '用户不存在'
    })
  }
})

module.exports = router;